// Close Rest-API
add_filter( 'rest_authentication_errors', function( $error ) {
  if (!empty($error)) {
    return $error;
  }
  if ( strpos($_SERVER['REQUEST_URI'], 'contact-form-7') == 0 && ! is_user_logged_in() ){
      return new WP_Error( 'rest_not_logged_in', 'You are not currently logged in.', array( 'status' => 401 ) );
  }
  global $wp_json_basic_auth_error;
  return $wp_json_basic_auth_error;
});